import 'babel-polyfill'
import promise from 'es6-promise' // 兼容 Promise
import Vue from 'vue'
import VueRouter from 'vue-router'
import info from './info.vue'

promise.polyfill()

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Info',
    component: info
  },
  {
    path: '/yixiang',
    name: 'PersonYixiang',
    component: function () {
      return import('./yinxiang.vue')
    }
  },
  {
    path: '/yixiangAdd',
    name: 'PersonYixiangAdd',
    component: function () {
      return import('./yinxiangAdd.vue')
    }
  },
  {
    path: '/work',
    name: 'PersonWork',
    component: function () {
      return import('./work.vue')
    }
  },
  {
    path: '/workAdd',
    name: 'PersonWorkAdd',
    component: function () {
      return import('./workAdd.vue')
    }
  },
  {
    path: '/project',
    name: 'PersonProject',
    component: function () {
      return import('./project.vue')
    }
  },
  {
    path: '/projectAdd',
    name: 'PersonProjectAdd',
    component: function () {
      return import('./projectAdd.vue')
    }
  },
  {
    path: '/study',
    name: 'PersonStudy',
    component: function () {
      return import('./study.vue')
    }
  },
  {
    path: '/studyAdd',
    name: 'PersonStudyAdd',
    component: function () {
      return import('./studyAdd.vue')
    }
  },
  {
    path: '/school',
    name: 'PersonSchool',
    component: function () {
      return import('./school.vue')
    }
  },
  {
    path: '/schoolAdd',
    name: 'PersonSchoolAdd',
    component: function () {
      return import('./schoolAdd.vue')
    }
  },
  {
    path: '/addposition',
    name: 'addPosition',
    component: function () {
      return import('./addPosition.vue')
    }
  },
  {
    path: '/skill',
    name: 'PersonSkill',
    component: function () {
      return import('./skill.vue')
    }
  },
  {
    path: '/skillAdd',
    name: 'PersonSkillAdd',
    component: function () {
      return import('./skillAdd.vue')
    }
  },
  {
    path: '/skillCertificationAdd',
    name: 'SkillCertificationAdd',
    component: function () {
      return import('./skillCertificationAdd.vue')
    }
  },
  {
    path: '/skillTrain',
    name: 'skillTrain',
    component: function () {
      return import('./skillTrain.vue')
    }
  },
  {
    path: '/enclosure',
    name: 'PersonEnclosure',
    component: function () {
      return import('./enclosure.vue')
    }
  }
]

const router = new VueRouter({
  routes
})
router.beforeEach((to, from, next) => {
  if (!localStorage.getItem('md_userInfo')) {
    window.location.href = 'index.html'
    return
  }
  next()
})
export default router
